package com.od.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.od.entity.City;
import com.od.utils.ProvinceCity;

@Mapper
public interface ProvinceCityMapper {
    @Select("SELECT * FROM province")
    @Results({
            @Result(property = "provinceId", column = "province_id"),
            @Result(property = "provinceName", column = "province_name"),
            @Result(property = "cities", column = "province_id", many = @Many(select = "selectCitiesByProvinceId"))
    })
    List<ProvinceCity> selectAllProvinces();

    @Select("SELECT * FROM city WHERE city_province = #{provinceId}")
    @Results({
            @Result(property = "cityId", column = "city_id"),
            @Result(property = "cityName", column = "city_name"),
            @Result(property = "cityProvince", column = "city_province")
    })
    List<City> selectCitiesByProvinceId(int provinceId);
}
